//
//  HWGroupChatQunViewController.m
//  HWanGame
//
//  Created by 陈道斌 on 2020/12/14.
//  Copyright © 2020 Chendaobin. All rights reserved.
//

#import "HWGroupChatQunViewController.h"
#import "HWquanliaoDeTableViewCell.h"
#import "HWTypeleibieModel.h"
#import "HWTypeleibieCollectionViewCell.h"
#import "XMGWebViewController.h"
#import "HWLoginController.h"






@interface HWGroupChatQunViewController ()<UITableViewDelegate,UITableViewDataSource,UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
@property(strong,nonatomic) UITableView *mainaTableVie;
@property(strong,nonatomic)NSMutableArray  *tuijianNsMuArr;
@property(strong,nonatomic)NSMutableArray  *listMuArr;

 
@property(strong,nonatomic) NSString *max_p;
@property(strong,nonatomic) NSString *p;
@property(strong,nonatomic) UIView *adddfootView;

@property(strong,nonatomic) UICollectionView *maincollectionView;
@property(strong,nonatomic) NSMutableArray *dataMuArr;
@property(strong,nonatomic) NSMutableArray *fenleiMuArr;
@property(strong,nonatomic) HWTypeleibieModel * seledeModel;


@property(strong,nonatomic) UITableView *otherTabeleView;





@end

@implementation HWGroupChatQunViewController




- (UITableView *)otherTabeleView {
    
    if (_otherTabeleView == nil) {
        
        
        _otherTabeleView = [[UITableView alloc]initWithFrame:CGRectMake(0, 164+54, kScreenW,kScreenH-CF_NavHeight-164-54) style:UITableViewStylePlain];
             _otherTabeleView.delegate = self;
         _otherTabeleView.dataSource = self;
         _otherTabeleView.tag = 200;
         _otherTabeleView.separatorStyle = UITableViewCellSeparatorStyleNone;
         _otherTabeleView.backgroundColor = [UIColor whiteColor];
    
    }
    
    
    return  _otherTabeleView;
    
    
}






-(UITableView *)mainaTableVie {
    
    if (_mainaTableVie == nil
        ) {
        
        
        _mainaTableVie = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH-CF_NavHeight-44-CF_TabbarHeight) style:UITableViewStylePlain];
        _mainaTableVie.delegate = self;
        _mainaTableVie.dataSource = self;
        _mainaTableVie.separatorStyle = UITableViewCellSeparatorStyleNone;
        _mainaTableVie.backgroundColor = [UIColor whiteColor];
        _mainaTableVie.tag = 100;
        _mainaTableVie.backgroundColor = RGB(247, 247, 247);


        
    }
    return   _mainaTableVie ;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    [self setupUI];
    

    
    //发送请求
   //  [self fasongqingqiu];
    
   //  [self addrefreshControl];

    [self addtableDefootview];
    
    // 添加
    
    
     [self addhudongHederView];
    
    
     [self addrefreshControl];
    
    // 查询分类
    [self chaxunqueryClassification];
    
  //   [self addhudongHederView];
  //  [self addrefreshControl];
    
    
    
}


- (void)addhudongHederView  {
    
    UIView *tupianView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 54)];
    tupianView.backgroundColor = [UIColor redColor];
     tupianView.backgroundColor = [UIColor whiteColor];
    [self.adddfootView  addSubview:tupianView];
    
    
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.scrollDirection  =  UICollectionViewScrollDirectionHorizontal;

  //    layout.minimumLineSpacing = 18;

//      CGFloat juanju  = (kScreenW - 24*CFLScaleValue*2-62*CFLScaleValue*3-78*CFLScaleValue)/2;
     // layout.minimumInteritemSpacing = 1;
    layout.minimumLineSpacing = 10;
   //   layout.headerReferenceSize = CGSizeMake(kScreenW, 142);  //设置headerView大小
      self.maincollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(12, 0, kScreenW-12, 54) collectionViewLayout:layout];
      // self.maincollectionView.showsHorizontalScrollIndicator = NO;
      self.maincollectionView.delegate = self;
      self.maincollectionView.dataSource = self;
      self.maincollectionView.alwaysBounceVertical = NO;
      //self.maincollectionView.pagingEnabled = YES;
      self.maincollectionView.backgroundColor = [UIColor whiteColor];
     self.maincollectionView.showsHorizontalScrollIndicator = NO;
       self.maincollectionView.showsVerticalScrollIndicator = NO;
   
     self.maincollectionView.contentInset =  UIEdgeInsetsMake(12, 0, 12, 12);
    
   //   self.maincollectionView.contentInset = UIEdgeInsetsMake(0, 24*CFLScaleValue, 0, 24*CFLScaleValue);
    //  [self.maincollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView"];  //  一定要设置
      [self.maincollectionView registerClass:[HWTypeleibieCollectionViewCell class] forCellWithReuseIdentifier:@"cellID"];
     //  [self.maincollectionView  registerNib:[UINib nibWithNibName:@"HWJinXuanCell" bundle:nil] forCellWithReuseIdentifier:@"cellID"];
      self.maincollectionView.userInteractionEnabled = YES;
      [tupianView   addSubview:self.maincollectionView];
    
    
    
     self.otherTabeleView.frame = CGRectMake(0, 54, kScreenW, self.adddfootView.height -54);
     self.otherTabeleView.backgroundColor = [UIColor whiteColor];
     [self.adddfootView addSubview:self.otherTabeleView];
    
    
    
    
    



    
}






// 查询分类
- (void)chaxunqueryClassification {
    
    
    NSDictionary *parametes = @{
                                @"ct" :  @"app",
                                @"ac" : @"fenlei",
                                @"ios" : @"1"
                                };
    
  //  [MBProgressHUD show:<#(NSString *)#>]
  //  [MBProgressHUD showMessage:@"正在加载" toView:nil];
   // [MBProgressHUD show:@"正在加载..."];
    self.dataMuArr = [[NSMutableArray alloc]init];
    
    
    [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
        
      
        NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
     //   [MBProgressHUD hideHUD];
        
        
        if ([codeStr intValue] == 1) {
         
          //  self.fenleiMuArr = [response[@"data"] mutableCopy];
           //  [MBProgressHUD  showError:@"加载失败"];
            self.fenleiMuArr  =  [HWTypeleibieModel mj_objectArrayWithKeyValuesArray:response[@"data"]];
            HWTypeleibieModel *mdol = self.fenleiMuArr[0];
            self.seledeModel = mdol;
            mdol.xuazhong = YES;
           //  [self.mainaTableVie.mj_header beginRefreshing];
            [self.maincollectionView reloadData];
            
            [self underRefresh];
            
            
            

        } else {
            
             [MBProgressHUD  showError:@"加载失败"];
            
        }
        NSLog(@"%@",response);
        
        
    } failure:^(NSString *error) {
      
        [MBProgressHUD  showError:@"加载失败"];
        
    }];
    
    
    
}






//
- (void)addtableDefootview {
    
    self.adddfootView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH-CF_NavHeight-44-CF_TabbarHeight-62*3-46+100)];
    self.adddfootView.backgroundColor = [UIColor whiteColor];
    self.mainaTableVie.tableFooterView = self.adddfootView;
     
    
    
    
}












-(void)setupUI {
    

    
    
    [self.view addSubview:self.mainaTableVie];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    
}



#pragma  mark ---- 添加刷新

- (void)addrefreshControl {
    
  //   self.otherTabeleView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(underRefresh)];
    
  //   [self.otherTabeleView.mj_header beginRefreshing];
    
     self.mainaTableVie.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(onRefresh)];
}


#pragma  mark --------- 下拉刷新
- (void)underRefresh {
    
    //    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    //        // 结束刷新
    //        [self.mainaTableVie.mj_header endRefreshing];
    //    });
    
    
    // [SVProgressHUD show];
    __weak typeof(self) weakSelf = self;
    
//
//    NSDictionary *parametes = @{
//                                @"type" : @"2",
//                                @"t" : @"0",
//                                @"ct" :  @"app",
//                                @"ac" : @"index"
//
//                                };
    
    
     
       HWTypeleibieModel *model  = self.seledeModel;
     
        
    
           NSString *userID = [HWLocallyStoredData getLoginUserID];
            int t =   [WMUtil  getRandomNumber:101 to:998];
            NSString *tString = [NSString stringWithFormat:@"%ld%d",[WMUtil getTimeSp],t];
             
           NSString *type = [NSString stringWithFormat:@"%@",model.id];
     
       
              NSString *sign = [NSString stringWithFormat:@"%@%@%@",userID,tString,@"fsd213ewdsadqwe2121213edsad"];
              NSString *signMD5 = [WMUtil md5HexDigest:sign];
//              NSDictionary *parametes = @{
//                                         @"ct" :  @"app",
//                                         @"ac" : @"qun_tuijian",
//                                         @"ios" : @"1",
//                                         @"uid" :userID,
//                                         @"p" : @"1",
//                                         @"type":type,
//
//
//                                         };
    
       NSDictionary *parametes = @{
                                        
                                            @"ios" : @"1",
                                            @"uid" :userID,
                                            @"p" : @"1",
                                            @"type":type,
                                            @"language":[HWjianzhiduiObject returnLanguageAcquisition],
                                     
                       
                                            };
    
    
     
    [HWWebUtils do4GetWithParameters:parametes  hiddenparameterStr:hwqun_tuijian progress:nil success:^(id response) {
         
         // [SVProgressHUD dismiss];

         NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
         
         
         // [SVProgressHUD dismiss];
               [self.mainaTableVie.mj_header endRefreshing];
               [self.mainaTableVie.mj_footer endRefreshing];
         
               [self.otherTabeleView.mj_header endRefreshing];
               [self.otherTabeleView.mj_footer endRefreshing];
               

         if ([codeStr intValue] == 1) {
             
             
             self.tuijianNsMuArr =  [HWqunliaoModel mj_objectArrayWithKeyValuesArray:response[@"data"][@"tuijian"]];
             self.listMuArr = [HWqunliaoModel mj_objectArrayWithKeyValuesArray:response[@"data"][@"list"]];
             
             
             self.max_p = [NSString stringWithFormat:@"%@",response[@"max_p"]];
             self.p =  [NSString stringWithFormat:@"%@",response[@"p"]];
             
             [self.mainaTableVie reloadData];
             [self.otherTabeleView  reloadData];
             
             
             

    
            
             
             
             
         } else {
             
             
                [self.mainaTableVie reloadData];
             
         }
         NSLog(@"%@",response);
         
         
     } failure:^(NSString *error) {
       
         
         
         // [SVProgressHUD dismiss];
               [self.mainaTableVie.mj_header endRefreshing];
               [self.mainaTableVie.mj_footer endRefreshing];
               
         
         
     }];
     
    
    
      
    
    
    
}

#pragma  mark ---------- 上拉刷新
- (void)onRefresh {
    
    
    
    if ([self.p intValue] > [self.max_p intValue]) {
    
        [self.mainaTableVie.mj_header endRefreshing];
        [self.mainaTableVie.mj_footer endRefreshing];
                 
        [self.otherTabeleView.mj_header endRefreshing];
       [self.otherTabeleView.mj_footer endRefreshing];
                       
        
    }
    
    
            HWTypeleibieModel *model  = self.seledeModel;
       
      
      
             NSString *userID = [HWLocallyStoredData getLoginUserID];
              int t =   [WMUtil  getRandomNumber:101 to:998];
              NSString *tString = [NSString stringWithFormat:@"%ld%d",[WMUtil getTimeSp],t];
               
             NSString *type = [NSString stringWithFormat:@"%@",model.id];
       
         
                NSString *sign = [NSString stringWithFormat:@"%@%@%@",userID,tString,@"fsd213ewdsadqwe2121213edsad"];
                NSString *signMD5 = [WMUtil md5HexDigest:sign];
//                NSDictionary *parametes = @{
//                                           @"ct" :  @"app",
//                                           @"ac" : @"qun_tuijian",
//                                           @"ios" : @"1",
//                                           @"uid" :userID,
//                                           @"p" : self.p,
//                                           @"type":type,
//
//
//                                           };
    
       NSDictionary *parametes = @{
                         
                            @"ios" : @"1",
                            @"uid" :userID,
                            @"p" : self.p,
                            @"type":type,
                            @"language":[HWjianzhiduiObject returnLanguageAcquisition],
                     
       
                            };
    
    
       
    [HWWebUtils do4GetWithParameters:parametes hiddenparameterStr:hwqun_tuijian  progress:nil success:^(id response) {
           
           // [SVProgressHUD dismiss];

           NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
           
           
           // [SVProgressHUD dismiss];
                 [self.mainaTableVie.mj_header endRefreshing];
                 [self.mainaTableVie.mj_footer endRefreshing];
           
                 [self.otherTabeleView.mj_header endRefreshing];
                 [self.otherTabeleView.mj_footer endRefreshing];
                 

           if ([codeStr intValue] == 1) {
               
               
               self.tuijianNsMuArr =  [HWqunliaoModel mj_objectArrayWithKeyValuesArray:response[@"data"][@"tuijian"]];
               
               
               NSArray *listMuArr1 = [HWqunliaoModel mj_objectArrayWithKeyValuesArray:response[@"data"][@"list"]];
               
               for (int i =0 ; i < listMuArr1.count; i++) {
                   [self.listMuArr  addObject: listMuArr1[i]];
                   
               }
               
               
            //    self.listMuArr = [HWqunliaoModel mj_objectArrayWithKeyValuesArray:response[@"data"][@"list"]];
               
               
               self.max_p = [NSString stringWithFormat:@"%@",response[@"max_p"]];
               self.p =  [NSString stringWithFormat:@"%@",response[@"p"]];
               
                [self.mainaTableVie reloadData];
               
                [self.otherTabeleView  reloadData];
               
               

      
              
               
               
               
           }
           NSLog(@"%@",response);
           
           
       } failure:^(NSString *error) {
         
           
           
           // [SVProgressHUD dismiss];
                 [self.mainaTableVie.mj_header endRefreshing];
                 [self.mainaTableVie.mj_footer endRefreshing];
                 
           
           
       }];
    
 
    

    
    
}




// 发送请求
- (void)fasongqingqiu {
    
    
    
           NSString *userID = [HWLocallyStoredData getLoginUserID];
           int t =   [WMUtil  getRandomNumber:101 to:998];
           NSString *tString = [NSString stringWithFormat:@"%ld%d",[WMUtil getTimeSp],t];
            
          NSString *type = [NSString stringWithFormat:@"%@",@"0"];
    
      
             NSString *sign = [NSString stringWithFormat:@"%@%@%@",userID,tString,@"fsd213ewdsadqwe2121213edsad"];
             NSString *signMD5 = [WMUtil md5HexDigest:sign];
             NSDictionary *parametes = @{
                                        @"ct" :  @"app",
                                        @"ac" : @"qun_tuijian",
                                        @"ios" : @"1",
                                        @"uid" :userID,
                                        @"p" : @"1",
                                        @"member_id":[HWLocallyStoredData getCode],
                                        
                                 
                        
                            
                                        };
    
    [HWWebUtils do3GetWithParameters:parametes progress:nil success:^(id response) {
        
        // [SVProgressHUD dismiss];

        NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];

        if ([codeStr intValue] == 1) {
            
            
            
   
           
            
            
            
        }
        NSLog(@"%@",response);
        
        
    } failure:^(NSString *error) {
      
        
        
        
        
        
    }];
    
    
}







#pragma mark ---------



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    

    
    if (tableView.tag == 100) {
        
        return 2;
        
    } else {
        
         return 1;
        
    }
    

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    
    
    
    if (tableView.tag == 100) {
        
        
        if (section   ==  0 ) {
              return  self.tuijianNsMuArr.count;
        } else {
            
            
            return 0;
        }
        
          
    } else {
        
       //  return 100;
        
          return  self.listMuArr.count;
    }
    
 

    
    
    
}




 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    
    if (tableView.tag == 100 ) {
        
         static NSString *cellID = @"cellID";
          
          HWquanliaoDeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
          
          if (!cell) {
              cell = [[NSBundle mainBundle]loadNibNamed:@"HWquanliaoDeTableViewCell" owner:nil options:nil].firstObject;
              
              
          }
          cell.tuijindataModel = self.tuijianNsMuArr[indexPath.row];
        //   cell.textLabel.text = @"ijdiio";
        cell.selectionStyle =  UITableViewCellSelectionStyleNone;
        
        [cell.jiaruButon addTarget:self action:@selector(tujiantap:) forControlEvents:UIControlEventTouchUpInside];
        
          
          
          return cell;
        
    } else  {
        
          static NSString *cellID = @"cellID";
          
          HWquanliaoDeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
          
          if (!cell) {
              cell = [[NSBundle mainBundle]loadNibNamed:@"HWquanliaoDeTableViewCell" owner:nil options:nil].firstObject;
              
              
          }
            cell.tuijindataModel = self.listMuArr[indexPath.row];
        //   cell.textLabel.text = @"ijdiio";
          
            cell.selectionStyle =  UITableViewCellSelectionStyleNone;
          
             [cell.jiaruButon addTarget:self action:@selector(fenleitap:) forControlEvents:UIControlEventTouchUpInside];
          return cell;
          
        
        
        
    }
    

}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    return 62;
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    
    if (tableView.tag == 100) {
        return  46;
    } else {
        
        
        return  1;
        
    }
   
    
   
    
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {

    return 1;



}


- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    
    
    if (tableView.tag == 200) {
        UIView  *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 1)];
           
        return view1;
        
        
    }
    
    
    
    UIView  *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 46)];
    view.backgroundColor = RGB(247, 247, 247);
    
    
    
    UIView *baiseView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, 46)];
    baiseView.backgroundColor = RGB(255, 255, 255);
    [view addSubview:baiseView];
    
    
//        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:baiseView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)];
//        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
//        maskLayer.frame = baiseView.bounds;
//        maskLayer.path = maskPath.CGPath;
//        baiseView.layer.mask = maskLayer;
    
    
        UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(12, 24,4,16)];
        
        view1.backgroundColor = RGB(248, 119, 6);
    //    view1.layer.cornerRadius = 10;
    //    view1.layer.masksToBounds = YES;
    //
        [baiseView addSubview:view1];
        
    
    
    UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(view1.right+6,20, 200, 26)];
               //     nameLabel.text = fanlilistArr[i];
        //  nameLabel.backgroundColor =  RGB(248, 119, 6);
         nameLabel.backgroundColor = [UIColor clearColor];
          nameLabel.textAlignment = NSTextAlignmentLeft;
          nameLabel.font = [UIFont systemFontOfSize:18];
          nameLabel.textColor = RGB(68, 68, 68);
    
   nameLabel.text = @"平台活动";
 //    nameLabel.font = [UIFont fontWithName:@"Helvetica-BoldOblique" size:20];//又粗又斜
     //     nameLabel.layer.cornerRadius = 8;
     //     nameLabel.layer.masksToBounds = YES;
    UIFontDescriptor * fontD = [nameLabel.font.fontDescriptor
    fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold
                    | UIFontDescriptorTraitItalic];
    nameLabel.font = [UIFont fontWithDescriptor:fontD size:0];

          nameLabel.text = @"平台活动";
       [baiseView addSubview:nameLabel];
    
    if (section == 0) {
        nameLabel.text = @"热门分类";
        nameLabel.text = [HWjianzhiduiObject keylocalization:@"热门分类"];
        
    } else {
        
        
         nameLabel.text = @"分栏板快";
        
         nameLabel.text = [HWjianzhiduiObject keylocalization:@"分栏板快"];
    }
    
    return  view;
    
    
    
    
    
}


- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {





    UIView  *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 1)];
    view.backgroundColor =RGB(247, 247, 247);


    UIView *baiseView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, 10)];
      baiseView.backgroundColor = RGB(255, 255, 255);

      [view addSubview:baiseView];

    view.backgroundColor = [UIColor whiteColor];
//          UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:baiseView.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];
//          CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
//          maskLayer.frame = baiseView.bounds;
//          maskLayer.path = maskPath.CGPath;
//          baiseView.layer.mask = maskLayer;
//



    return  view;



}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    HWqunliaoModel  *model = nil;
    
    if ([[HWLocallyStoredData getLoginUserID] isEqualToString:@""]) {
        
        
            HWLoginController  *login = [[HWLoginController alloc]init];
            [self.navigationController pushViewController:login animated:YES];
        
        
           return;
    
    }
    
    
    if (tableView.tag == 100) {
        
        model  =  self.tuijianNsMuArr[indexPath.row];
        
        
        
        
    } else {
        
        
           model  =  self.listMuArr[indexPath.row];
        
        
        
    }
    
    
    
    if ([model.join isEqualToString:@"0"]) {
         
        [MBProgressHUD showError:@"请先加入群聊"];
        
        return;
    }
    
    XMGWebViewController *webVc = [[XMGWebViewController alloc] init];
        webVc.url = [NSURL URLWithString:model.url];
       [self.navigationController pushViewController:webVc animated:YES];
    
    
    
    
    
    
    
    
    
}




#pragma mark --------- UICollectionViewDelegate


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
  //  5
    return self.fenleiMuArr.count;
}







- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    HWTypeleibieCollectionViewCell *cell =  [collectionView dequeueReusableCellWithReuseIdentifier:@"cellID" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
    HWTypeleibieModel  *model = self.fenleiMuArr[indexPath.row];
    cell.model = model;
    

    return cell;
    
    
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    return CGSizeMake(75,30);
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    DLog(@"12334");
    
    
       for (int i = 0; i < self.fenleiMuArr.count; i++) {
            HWTypeleibieModel *model  =   self.fenleiMuArr[i];
             model.xuazhong = NO;
       }
       HWTypeleibieModel *model  =   self.fenleiMuArr[indexPath.row];
       model.xuazhong = YES;
       [self.maincollectionView reloadData];
    
       self.seledeModel = model;
      //  [self.mainaTableVie.mj_header beginRefreshing];
       
        [self   underRefresh];
    
       
       NSLog(@"点击了第%ld分item",(long)indexPath.item);
       
    
    
}



- (void)tujiantap:(UIButton *)sender {
    
    NSLog(@"%@",[[sender superview] superview] );
    NSLog(@"%@",[[sender superview] superview] );
    
    HWquanliaoDeTableViewCell *cell = (HWquanliaoDeTableViewCell *)[[sender superview] superview];
    
    NSIndexPath *inex  =   [self.mainaTableVie indexPathForCell:cell];
    
    
    HWqunliaoModel *mode =     self.tuijianNsMuArr[inex.row];
    
    
    NSString *userID = [HWLocallyStoredData getLoginUserID];
             int t =   [WMUtil  getRandomNumber:101 to:998];
             NSString *tString = [NSString stringWithFormat:@"%ld%d",[WMUtil getTimeSp],t];
              
            NSString *type = [NSString stringWithFormat:@"%@",@"0"];
      
        
               NSString *sign = [NSString stringWithFormat:@"%@%@%@",userID,tString,@"fsd213ewdsadqwe2121213edsad"];
               NSString *signMD5 = [WMUtil md5HexDigest:sign];
               NSDictionary *parametes = @{
                                          @"ct" :  @"app",
                                          @"ac" : @"join_qun",
                                          @"t" :tString,
                                          @"ios" : @"1",
                                          @"uid" :userID,
                                          @"id": mode.id,
                                          @"sign":signMD5,
                                          @"member_id":[HWLocallyStoredData getCode],
                                          
            
                                          };
      
      [HWWebUtils do3GetWithParameters:parametes progress:nil success:^(id response) {
          
          // [SVProgressHUD dismiss];

          NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];

          if ([codeStr intValue] == 1) {
              
              
              mode.join = @"1";
              
              [cell.jiaruButon setTitle:@"已加入" forState:UIControlStateNormal];
              
             [self underRefresh];
              
              
              
          }
          NSLog(@"%@",response);
          
          
      } failure:^(NSString *error) {
        
          
          
          
          
          
      }];
    
    
    
    
    
    
    
    
    
    
     
    
    
    
    
}





// fei
- (void)fenleitap:(UIButton *)sender {
    
    NSLog(@"%@",[[sender superview] superview]);
    
    HWquanliaoDeTableViewCell *cell = (HWquanliaoDeTableViewCell *)[[sender superview] superview];
       
       NSIndexPath *inex  =   [self.otherTabeleView indexPathForCell:cell];
    
    
      HWqunliaoModel *mode =     self.listMuArr[inex.row];
    
    
    
    
    NSString *userID = [HWLocallyStoredData getLoginUserID];
              int t =   [WMUtil  getRandomNumber:101 to:998];
              NSString *tString = [NSString stringWithFormat:@"%ld%d",[WMUtil getTimeSp],t];
               
             NSString *type = [NSString stringWithFormat:@"%@",@"0"];
       
         
                NSString *sign = [NSString stringWithFormat:@"%@%@%@",userID,tString,@"fsd213ewdsadqwe2121213edsad"];
                NSString *signMD5 = [WMUtil md5HexDigest:sign];
                NSDictionary *parametes = @{
                                           @"ct" :  @"app",
                                           @"ac" : @"join_qun",
                                           @"t" :tString,
                                           @"ios" : @"1",
                                           @"uid" :userID,
                                           @"id": mode.id,
                                            @"sign":signMD5,
                                           @"member_id":[HWLocallyStoredData getCode],
                                           
             
                                           };
       
       [HWWebUtils do3GetWithParameters:parametes progress:nil success:^(id response) {
           
           // [SVProgressHUD dismiss];

           NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];

           if ([codeStr intValue] == 1) {
               
               
               mode.join = @"1";
               
               [cell.jiaruButon setTitle:@"已加入" forState:UIControlStateNormal];
               
               [self underRefresh];
               
               
               
               
           }
           NSLog(@"%@",response);
           
           
       } failure:^(NSString *error) {
         
           
           
           
           
           
       }];
    
    
    
    
    
    
    
    
    
    
    
     
    
    
    NSLog(@"%d",inex.row);
    
}

















@end
